<template>
  <div class="modal-overlay" @click="$emit('close')">
    <div class="modal" @click.stop>
      <h2>确认订单</h2>
      
      <div class="order-summary">
        <h3>订单商品</h3>
        <div v-for="item in cartItems" :key="item.id" class="order-item">
          <span>{{ item.name }} x {{ item.quantity }}</span>
          <span>¥{{ (item.price * item.quantity).toFixed(2) }}</span>
        </div>
        <div class="order-total">
          <strong>总计: ¥{{ total.toFixed(2) }}</strong>
        </div>
      </div>

      <form @submit.prevent="submitOrder" class="order-form">
        <div class="form-group">
          <label>姓名:</label>
          <input v-model="orderForm.name" type="text" required />
        </div>
        
        <div class="form-group">
          <label>电话:</label>
          <input v-model="orderForm.phone" type="tel" required />
        </div>
        
        <div class="form-group">
          <label>地址:</label>
          <textarea v-model="orderForm.address" required></textarea>
        </div>
        
        <div class="form-group">
          <label>备注:</label>
          <textarea v-model="orderForm.notes"></textarea>
        </div>

        <div class="modal-actions">
          <button type="button" @click="$emit('close')">取消</button>
          <button type="submit" class="submit-btn">提交订单</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

defineProps(['cartItems', 'total'])
const emit = defineEmits(['close', 'submit-order'])

const orderForm = ref({
  name: '',
  phone: '',
  address: '',
  notes: ''
})

const submitOrder = () => {
  emit('submit-order', orderForm.value)
}
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.submit-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
}
</style>